﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class MyLy_MylyInformationc : System.Web.UI.Page
{

    BLL.UserBean bean = new UserBean();
    WebUtility utility = new WebUtility();
    DataTable table = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WebUtility.BindList("行业属性", ddl_Vocation);

            string mobile = "";
            if (Session["LoginUser"] == null)
            {
                Response.Redirect(WebUtility.getWebRootPath() + "/Login/Login.aspx");
            }
            else
            {
                mobile = Session["LoginUser"].ToString();
                table = bean.GetCustomInfo(mobile);

                if (table.Rows.Count > 0)
                {
                    this.mobilePhone.Text = table.Rows[0]["LoginID"].ToString();
                    this.realName.Text = table.Rows[0]["KHLXB_KHMC"].ToString();
                    this.phone.Text = table.Rows[0]["KHLXB_LXDH"].ToString();
                    this.email.Text = table.Rows[0]["EMAIL"].ToString();
                    if (table.Rows[0]["KHLXB_KHLX"].ToString() == "")
                    {
                        this.ddl_Vocation.SelectedIndex = 0;
                    }
                    else
                    {
                        this.ddl_Vocation.SelectedItem.Text = table.Rows[0]["KHLXB_KHLX"].ToString();
                    }
                    this.txt_Address.Text = table.Rows[0]["KHLXB_TXDZ"].ToString();
                    this.txt_ZipCode.Text = table.Rows[0]["KHLXB_YB"].ToString();                    
                }
            }
        }
    }

    protected void btn_Update_Click(object sender, ImageClickEventArgs e)
    {
        string mobileNO = this.mobilePhone.Text;
        string name = this.realName.Text;
        string phoneNO = this.phone.Text;
        string email = this.email.Text;
        string vocation = this.ddl_Vocation.SelectedIndex != 0 ? this.ddl_Vocation.SelectedItem.Text : "";
        string address = this.txt_Address.Text;
        string zipCode = this.txt_ZipCode.Text;

        int count = bean.UpdateCompanyInfo(mobileNO, name, email, phoneNO, vocation, address, zipCode);
        if (count > 0)
        {
            utility.AlertMsg("信息修改成功！");
            //Response.Redirect(WebUtility.getWebRootPath() + "/MyLy/Mylyindex.aspx");
        }
        else
        {
            utility.AlertMsg("信息修改失败！");
            return;
        }
    }
}
